package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.customer.domain.vo.MallBannerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.MallBanner;
import com.ktgj.customer.service.IMallBannerService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 商城轮播Controller
 * 
 * @author ruoyi
 * @date 2022-06-13
 */
@RestController
@RequestMapping("/banner")
public class MallBannerController extends BaseController
{
    @Autowired
    private IMallBannerService mallBannerService;

    /**
     * 查询商城轮播列表
     */
    @PreAuthorize(hasPermi = "customer:banner:list")
    @GetMapping("/list")
    public TableDataInfo list(MallBanner mallBanner)
    {
        startPage();
        List<MallBanner> list = mallBannerService.selectMallBannerList(mallBanner);
        return getDataTable(list);
    }

    /**
     * 导出商城轮播列表
     */
    @PreAuthorize(hasPermi = "customer:banner:export")
    @Log(title = "商城轮播", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallBanner mallBanner) throws IOException
    {
        List<MallBanner> list = mallBannerService.selectMallBannerList(mallBanner);
        ExcelUtil<MallBanner> util = new ExcelUtil<MallBanner>(MallBanner.class);
        util.exportExcel(response, list, "商城轮播数据");
    }

    /**
     * 获取商城轮播详细信息
     */
    @PreAuthorize(hasPermi = "customer:banner:query")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return AjaxResult.success(mallBannerService.selectMallBannerById(bannerId));
    }

    /**
     * 新增商城轮播
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MallBanner mallBanner)
    {
        return toAjax(mallBannerService.insertMallBanner(mallBanner));
    }

    /**
     * 修改商城轮播
     */
    @PreAuthorize(hasPermi = "customer:banner:edit")
    @Log(title = "商城轮播", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallBanner mallBanner)
    {
        return toAjax(mallBannerService.updateMallBanner(mallBanner));
    }

    /**
     * 删除商城轮播
     */
    @PreAuthorize(hasPermi = "customer:banner:remove")
    @Log(title = "商城轮播", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(mallBannerService.deleteMallBannerByIds(bannerIds));
    }

    /**
     * 轮播管理列表
     * @param map
     * @return
     */
    @PostMapping("/mallBannerList")
    public TableDataInfo mallBannerList(@RequestBody Map<String, Object> map) {
        startPage();
        Long typeId = Long.valueOf(map.get("typeId").toString());
        Long apptypeId = Long.valueOf(map.get("apptypeId").toString());
        Long jumbtypeId = Long.valueOf(map.get("jumbtypeId").toString());
        String title = String.valueOf(map.get("title"));
        List<MallBannerVO> mallBannerVOS = mallBannerService.mallBannerList(typeId, apptypeId, jumbtypeId, title);
        return getDataTable(mallBannerVOS);
    }

    /**
     * Banner图详情
     * @param map
     * @return
     */
    @PostMapping("/mallBannerById")
    public AjaxResult mallBannerById(@RequestBody Map<String, Long> map) {
        Long bannerId = map.get("bannerId");
        MallBannerVO mallBannerVO = mallBannerService.mallBannerById(bannerId);
        return AjaxResult.success(mallBannerVO);
    }

    /**
     * 修改Banner图详情
     * @param banner
     * @return
     */
    @PostMapping("/updateMallBanner")
    public AjaxResult updateMallBanner(@RequestBody MallBannerVO banner) {
        return toAjax(mallBannerService.updateMallBanner(banner));
    }

    /**
     * 删除Banner图
     * @param map
     * @return
     */
    @PostMapping("/deleteMallBanner")
    public AjaxResult deleteMallBanner(@RequestBody Map<String, Long> map) {
        Long bannerId = map.get("bannerId");
        return toAjax(mallBannerService.deleteMallBanner(bannerId));
    }

    /**
     * 商城轮播
     * @return
     */
    @PostMapping("/mallBanner")
    public AjaxResult mallBanner() {
        List<MallBannerVO> mallBanner = mallBannerService.mallBanner();
        return AjaxResult.success(mallBanner);
    }
}
